package com.lx.gulimall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author lixun Email:lx3027@126.com
 * @create 2021-08-12 15:35
 */
public class OrderConfirmVo {

    /**
     * 收货地址 `ums_member_receive_address`
     */
    @Setter
    @Getter
    private List<MemberAddressVo> address;

    /**
     * 所有被选中的购物项
     */
    @Setter
    @Getter
    private List<OrderItemVo> items;

    // 发票信息……

    // 优惠劵信息……

    /**
     * 积分信息
     */
    @Setter
    @Getter
    private Integer integration;

    /**
     * 防重令牌
     */
    @Getter
    @Setter
    private String orderToken;

    @Getter
    @Setter
    Map<Long,Boolean> stocks;

    public Integer getCount() {
        Integer count = 0;
        if (items != null) {
            for (OrderItemVo item : items) {
                count += item.getCount();
            }
        }
        return count;
    }

    /**
     * 订单的总额
     */
    //private BigDecimal total;
    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if (items != null) {
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

    /**
     * 应付价格
     */
    //private BigDecimal payPrice;
    public BigDecimal getPayPrice() {
        return getTotal();
    }
}

